<!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-08-23 14:00:00
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-09-23 10:10:06
 * @FilePath: \newMould_BHZ\src\views\TensionAndGrout\TensionManage\Tension_task_listText.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>

            <!-- <el-button
              type="primary"
              icon="el-icon-search"
              size="small"
              v-if="yj_view"
              @click="editText(fId)"
              >查看
            </el-button> -->
            <el-button
              type="primary"
              icon="el-icon-circle-plus-outline"
              size="small"
              v-if="getList.modelType == '0' && yj_add == true"
              @click="operate(0)"
              >新增</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_edit == true"
              @click="operate(1)"
              >编辑</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '0' && yj_submit == true"
              @click="SubmitText(rowInfo)"
              >提交</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '0' && yj_delete == true"
              @click="rowDelete(rowInfo)"
              >删除</el-button
            >
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          @openDialog="openDialog"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!-- 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="详情拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="publicForm" style="height: 400px">
                <publicForm
                  ref="publicForm"
                  lableWidth="100px"
                  :formObj="formObj"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>

              <div style="height: 50px"></div>
            </div>
            <div class="newlyAdded_btn" v-if="btnShow">
              <el-button type="primary" @click="yj_saveForm()">
                保存
              </el-button>
              <el-button type="warning" @click="dialogEditVisible = false">
                关闭
              </el-button>
            </div>
          </div>
        </el-dialog>
      </div>
      <!-- WBS -->
      <div class="Control-1 mechanism_dialogS closure wbs">
        <el-dialog
          title="请选择WBS数据"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible_wbs"
          v-loading="loadingEditDialog_wbs"
          element-loading-text="WBS数据拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 45px; height: 100%">
              <el-table
                ref="multipleTable"
                :data="tableData_Wbs"
                style="width: 100%"
                height="100%"
                lazy
                :load="treeLoad"
                :tree-props="{
                  children: 'children',
                  hasChildren: 'fHaschildren',
                }"
                row-key="fNodeid"
                v-loading="loading"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.2)"
                :row-class-name="tableRowClassName"
                border
                stripe
                highlight-current-row
                @current-change="handleCurrentChange"
              >
                <el-table-column
                  fixed
                  type="index"
                  label="序号"
                  width="50"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="fName"
                  label="工程部位"
                  min-width="200"
                  style="display: flex"
                >
                  <template slot-scope="scope">
                    <a href="javascript:;" :title="scope.row.fName">
                      {{ scope.row.fName }}
                    </a>
                  </template>
                </el-table-column>

                <el-table-column
                  prop="fStartstationtype"
                  label="开始桩号类型"
                  align="center"
                  width="100"
                >
                  <template slot-scope="scope">
                    <a href="javascript:;" :title="scope.row.fStartstationtype">
                      {{ scope.row.fStartstationtype }}
                    </a>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="fStartstationkilometers"
                  label="开始桩号公里数"
                  align="center"
                  width="110"
                >
                  <template slot-scope="scope">
                    <a
                      href="javascript:;"
                      :title="scope.row.fStartstationkilometers"
                    >
                      {{ scope.row.fStartstationkilometers }}
                    </a>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="fStartstationmeters"
                  label="开始桩号长度(米)"
                  align="center"
                  width="120"
                >
                  <template slot-scope="scope">
                    <a
                      href="javascript:;"
                      :title="scope.row.fStartstationmeters"
                    >
                      {{ scope.row.fStartstationmeters }}
                    </a>
                  </template>
                </el-table-column>

                <el-table-column
                  prop="fEndstationtype"
                  label="结束桩号类型"
                  align="center"
                  width="100"
                >
                  <template slot-scope="scope">
                    <a href="javascript:;" :title="scope.row.fEndstationtype">
                      {{ scope.row.fEndstationtype }}
                    </a>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="fEndstationkilometers"
                  label="结束桩号公里数"
                  align="center"
                  width="110"
                >
                  <template slot-scope="scope">
                    <a
                      href="javascript:;"
                      :title="scope.row.fEndstationkilometers"
                    >
                      {{ scope.row.fEndstationkilometers }}
                    </a>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="fEndstationmeters"
                  label="结束桩号长度(米)"
                  align="center"
                  width="120"
                >
                  <template slot-scope="scope">
                    <a href="javascript:;" :title="scope.row.fEndstationmeters">
                      {{ scope.row.fEndstationmeters }}
                    </a>
                  </template>
                </el-table-column>

                <el-table-column
                  prop="fWbsstructuretype"
                  label="结构类型"
                  align="center"
                  width="110"
                >
                  <template slot-scope="scope">
                    <a href="javascript:;" :title="scope.row.fWbsstructuretype">
                      {{ scope.row.fWbsstructuretype }}
                    </a>
                  </template>
                </el-table-column>
              </el-table>
              <!-- <div style="height: 20px"></div> -->
            </div>
            <div class="newlyAdded_btn" v-if="btnShow">
              <el-button type="primary" @click="saveFrom()"> 保存 </el-button>
              <el-button type="warning" @click="deleFrom()"> 关闭 </el-button>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getTensioningTaskByfId, //详情
  getTensioningTaskList, //列表
  saveTensioningTask, //保存
  deleteTensioningTask, //删除
  submitTensioningTask, //提交
  getTensioningTaskNo, //任务单号
  getStationmachineList, //梁场
  getMachineListByStationId, //压浆机
  getWbsList, //WBS
  endTensioningTask, //提交未完成转变
} from "@/api/request.js";
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项

export default {
  inject: ["reload"],
  name: "Grout_task_list_RuicangText",
  data() {
    return {
      name: "Grout_task_list_RuicangText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_submit: null,
      radio: "待办",
      // 列表
      getList: {
        userId: "",
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        machineId: "", // 压浆机id
        fProjectposition: "", //工程部位模糊查询
        taskNo: "", //任务单模糊查询
        fStatus: "", //状态
        keyType: "2", //张拉 1 压浆 2 必填
        modelType: "0",
        fNote: "1", //新加参数 瑞仓1   其他0
      },
      loading: false, //列表转载
      table_config: formJs.StateTable_config,
      tableData: [], //表格列表数据列表
      rowInfo: {
        fId: "",
      }, //列表当前行信息
      // 列表

      // 弹框
      timeYMD: null, //当前日期
      timeYmdHms: null,
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formObj: formJs.formState,
      formObjLook: formJs.formState, //查看
      formObjText: formJs.formStateText, //编辑
      formData: {
        fId: "", //id
        fCompanyid: "", //标段id
        fCompanyname: "", //标段名称
        fProjectid: "", //项目id
        fProjectname: "", //项目名称
        fTaskno: "", //任务单号
        fBeamid: "", //梁场编号
        fBeamname: "", //梁场名称
        fBeamrealname: "", //梁名称
        fAge: "", //龄期
        fMachineid: "", //设备编号
        fMachinename: "", //设备名称
        fWbsid: "", //工程部位id
        fWbsname: "", //工程部位
        fConcretedesignstrength: "", //混凝土设计强度(张拉) / 孔道类型(压浆)
        fPlantensioningdates: "", //计划张拉日期
        fTensioningforce: "", //设计张拉力
        fBeamtype: "", //梁型
        fBeamnumber: "", //梁号
        fPouringdates: "", //浇筑日期
        fProcessnum: "", //孔道数
        fDesigndensity: "", //设计密度(压浆)
        fTheoreticalslurry: "", //理论浆量(压浆)
        fTaskuserid: "", //提交人id
        fTaskusername: "", //提交人
        fTaskdates: "", //创建时间
        fStatus: "未完成", //状态
        fNote: "2", //1 张拉 2压浆
        fWbsparentid:""
      },
      bhzDataList: [], //梁场
      bhjDataList: [], //压浆机
      // 弹框
      // wbs树
      WbsRow: null,
      dialogEditVisible_wbs: false,
      loadingEditDialog_wbs: false,
      tableData_Wbs: [],
      // wbs树

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
    console.log(this.userInfo);
    this.getList = {
      fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      startDates: "", // 开始时间
      endDates: "", // 截至时间
      machineId: "", // 压浆机id
      fProjectposition: "", //工程部位模糊查询
      taskNo: "", //任务单模糊查询
      fStatus: "", //状态
      keyType: "2", //张拉 1 压浆 2 必填
      modelType: "0", // 0代办 1已办  2表示列表页查询
      fNote: "1", //新加参数 瑞仓1   其他0
    };
    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);

    this.table_config.operation.cols = [
      {
        prop: "fStatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];

    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "未完成") {
        color = "red !important";
      } else if (rowData == "已完成") {
        color = "green !important";
      } else {
        color = "#409eff !important";
      }
      return color;
    };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("GxBack-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_submit = btnStr.includes("yj_submit");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_submit = true;
      }
    },

    modelType(e) {
      this.rowInfo = "";
      this.fId = "";
      this.getList.userId = this.userInfo.userId;
      if (e == "待办") {
        this.getList.modelType = "0";
      } else {
        this.getList.modelType = "1";
      }
      this.yj_searchForm(this.getList);
    },

    // 获取列表数据
    yj_searchForm(id) {
      this.loading = true;
      this.tableData = [];
      getTensioningTaskList(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    operate(num) {
      this.recordfiles = [];
      this.formObj = this.formObjText;
      this.btnShow = true;

      if (num == 0) {
        this.dialogTitle = "新增";
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;

        this.formData = {
          fId: "", //id
          fCompanyid: "", //标段id
          fCompanyname: "", //标段名称
          fProjectid: "", //项目id
          fProjectname: "", //项目名称
          fTaskno: "", //任务单号
          fBeamid: "", //梁场编号
          fBeamname: "", //梁场名称
          fBeamrealname: "", //梁名称
          fAge: "", //龄期
          fMachineid: "", //设备编号
          fMachinename: "", //设备名称
          fWbsid: "", //工程部位id
          fWbsname: "", //工程部位
          fConcretedesignstrength: "", //混凝土设计强度(张拉) / 孔道类型(压浆)
          fPlantensioningdates: "", //计划张拉日期
          fTensioningforce: "", //设计张拉力
          fBeamtype: "", //梁型
          fBeamnumber: "", //梁号
          fPouringdates: "", //浇筑日期
          fProcessnum: "", //孔道数
          fDesigndensity: "", //设计密度(压浆)
          fTheoreticalslurry: "", //理论浆量(压浆)
          fTaskuserid: "", //提交人id
          fTaskusername: "", //提交人
          fTaskdates: "", //创建时间
          fStatus: "未完成", //状态
          fNote: "2", //1 张拉 2压浆
          fWbsparentid:""
        };
        this.formObjText[6].options = [];
        this.getConcrete();
        this.mixingPlantList(0, this.userInfo.companyId);
      } else if (num == 1) {
        this.dialogTitle = "编辑";
        if (this.rowInfo.fId != "" && this.rowInfo.fId != null) {
          if (this.rowInfo.fStatus == "未提交") {
            var data = {
              fCompanyid: this.rowInfo.fCompanyid, //标段id
              fId: this.rowInfo.fId, //数据id
            };
            this.getDetails(data);
            // this.getConcrete();
          } else {
            return this.$message.error('请选择状态为"未提交"的数据！');
          }
        } else {
          return this.$message.error("请先选择需要编辑的数据");
        }
      }
    },

    // 任务单号
    getConcrete() {
      var data = {
        fCompanyid: this.userInfo.companyId, //标段id
        keyType: "2", ////张拉 1 压浆 2 必填
      };
      getTensioningTaskNo(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.Taskno = res.data.yjQmpMsTensioningtask.fTaskno;
            this.formData = {
              fId: "", //id
              fCompanyid: this.userInfo.companyId, //标段id
              fCompanyname: this.userInfo.companyName, //标段名称
              fProjectid: this.userInfo.projectId, //项目id
              fProjectname: this.userInfo.projectName, //项目名称
              fTaskno: this.Taskno, //任务单号
              fBeamid: "", //梁场编号
              fBeamname: "", //梁场名称
              fMachineid: "", //设备编号
              fMachinename: "", //设备名称
              fWbsid: "", //工程部位id
              fWbsname: "", //工程部位
              fConcretedesignstrength: "", //混凝土设计强度(张拉) / 孔道类型(压浆)
              fPlantensioningdates: "", //计划张拉日期
              fTensioningforce: "", //设计张拉力
              fBeamtype: "", //梁型
              fBeamnumber: "", //梁号
              fPouringdates: "", //浇筑日期
              fBeamrealname: "", //梁名称
              fAge: "", //龄期
              fProcessnum: "", //孔道数
              fDesigndensity: "", //设计密度(压浆)
              fTheoreticalslurry: "", //理论浆量(压浆)
              fTaskuserid: this.userInfo.userId, //提交人id
              fTaskusername: this.userInfo.realName, //提交人
              fTaskdates: this.timeYmdHms, //创建时间
              fStatus: "未完成", //状态
              fNote: "2", //1 张拉 2压浆
              fWbsparentid:""
            };
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 保存
    yj_saveForm() {
      if (this.$refs.publicForm.submitForm()) {
        var saveData = {
          fId: this.formData.fId, //id
          fCompanyid: this.formData.fCompanyid, //标段id
          fCompanyname: this.formData.fCompanyname, //标段名称
          fProjectid: this.formData.fProjectid, //项目id
          fProjectname: this.formData.fProjectname, //项目名称
          fTaskno: this.formData.fTaskno, //任务单号
          fBeamid: this.formData.fBeamid, //梁场编号
          fBeamname: this.formData.fBeamname, //梁场名称
          fMachineid: this.formData.fMachineid, //设备编号
          fMachinename: this.formData.fMachinename, //设备名称
          fWbsid: this.formData.fWbsid, //工程部位id
          fWbsname: this.formData.fWbsname, //工程部位
          fConcretedesignstrength: this.formData.fConcretedesignstrength, //混凝土设计强度(张拉) / 孔道类型(压浆)
          fPlantensioningdates: this.formData.fPlantensioningdates, //计划张拉日期
          fTensioningforce: this.formData.fTensioningforce, //设计张拉力
          fBeamtype: this.formData.fBeamtype, //梁型
          fBeamnumber: this.formData.fBeamnumber, //梁号
          fPouringdates: this.formData.fPouringdates, //浇筑日期
          fBeamrealname: this.formData.fBeamrealname, //梁名称
          fAge: this.formData.fAge, //龄期
          fProcessnum: this.formData.fProcessnum, //孔道数
          fDesigndensity: this.formData.fDesigndensity, //设计密度(压浆)
          fTheoreticalslurry: this.formData.fTheoreticalslurry, //理论浆量(压浆)
          fTaskuserid: this.formData.fTaskuserid, //创建人id
          fTaskusername: this.formData.fTaskusername, //创建人
          fTaskdates: this.formData.fTaskdates, //创建时间
          fStatus: this.formData.fStatus, //状态
          fNote: "2", //1 张拉 2压浆
          userId: this.userInfo.userId, //提交人id
          userName: this.userInfo.realName, //提交人
          fWbsparentid:this.formData.fWbsparentid
        };
        saveTensioningTask(saveData)
          .then((res) => {
            if (res.errcode == 0) {
              this.yj_searchForm(this.getList);
              this.dialogEditVisible = false;
              this.$message.success("新增成功");
            } else {
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log(error);
          });
      } else {
        console.log("error");
      }
    },

    // 提交
    SubmitText(row) {
      if (row.fId != "" && row.fId != null) {
        if (row.fStatus == "未提交") {
          this.$confirm("是否继续提交?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              submitTensioningTask({
                fId: row.fId,
                fCompanyid: this.rowInfo.fCompanyid,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("提交成功");
                  } else {
                    this.$message.error("提交失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("提交失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消提交");
            });
        } else {
          return this.$message.error('请选择状态为"未提交"的数据！');
        }
      } else {
        return this.$message.error("请先选择需要提交的数据");
      }
    },

    // 删除
    rowDelete(row) {
      if (row.fId != "" && row.fId != null) {
        if (row.fStatus == "未提交") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deleteTensioningTask({ fId: row.fId, fCompanyid:row.fCompanyid })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          return this.$message.error('请选择状态为"未提交"的数据！');
        }
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },
    // 详情
    getDetails(data) {
      this.loadingEditDialog = true; //弹框loading
      this.dialogEditVisible = true;
      this.formData = this.$options.data.call(this).formData;
      getTensioningTaskByfId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loadingEditDialog = false;
            // that.dialogEditVisible = true;
            that.formData = res.data.yjQmpMsTensioningtask;
            if (this.dialogTitle == "编辑") {
              if (
                this.formData.fCompanyname == "" ||
                this.formData.fCompanyname == null
              ) {
                this.formData.fCompanyid = this.userInfo.companyId; //标段id
                this.formData.fCompanyname = this.userInfo.companyName; //标段名称
                this.mixingPlantList(0, this.userInfo.companyId);
              } else {
                this.mixingPlantList(0, this.formData.fCompanyid);
              }

              if (
                this.formData.fProjectname == "" ||
                this.formData.fProjectname == null
              ) {
                this.formData.fProjectid = this.userInfo.projectId; //项目id
                this.formData.fProjectname = this.userInfo.projectName; //项目名称
              }

              if (
                this.formData.fTaskusername == "" ||
                this.formData.fTaskusername == null
              ) {
                this.formData.fTaskuserid = this.userInfo.id; //创建人id
                this.formData.fTaskusername = this.userInfo.userName; //创建人姓名
              }
              if (
                this.formData.fTaskdates == "" ||
                this.formData.fTaskdates == null
              ) {
                this.formData.fTaskdates = this.timeYmdHms; //创建时间
              }

              if (
                (this.formData.fBeamname == "" ||
                  this.formData.fBeamname == null) &&
                (this.formData.fBeamid == "" || this.formData.fBeamid == null)
              ) {
                this.formData.fMachinename = ""; //设备名称
                this.formData.fMachineid = ""; //设备编号
                this.formObjText[6].options = [];
              } else {
                this.getbhjDataMethods(this.formData.fBeamid, 5);
              }
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialog = false;
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
          this.loadingEditDialog = false;
        });
    },

    // 点击查看
    yj_viewForm(row, label) {
      if (label == "任务单号") {
        this.formObj = this.formObjLook;
        var id = row.fId;
        if (id != "" && id != null) {
          this.dialogTitle = "查看";
          this.btnShow = false;
          var data = {
            fCompanyid: row.fCompanyid, //标段id
            fId: row.fId, //数据id
          };
          this.getDetails(data);
        } else {
          return this.$message.error("请先选择需要查看的数据");
        }
      }
    },
    // 任务单完成状态
    openDialog(row) {
      if (row.fStatus == "未完成") {
        this.$confirm('是否将"未完成"提交为"已完成"?', "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            endTensioningTask({
              fId: row.fId,
              fCompanyid: row.fCompanyid,
              userId: this.userInfo.userId,
              userName: this.userInfo.realName,
            })
              .then((res) => {
                if (res.errcode == 0) {
                  this.loading = false;
                  this.yj_searchForm(this.getList);
                  this.$message.success("提交成功");
                } else {
                  this.$message.error("提交失败", res.msg);
                  this.loading = false;
                }
              })
              .catch(() => {
                this.loading = false;
              });
          })
          .catch(() => {
            this.$message("取消提交");
          });
      }
    },
    // 获取梁场
    mixingPlantList(num, id) {
      var data = {
        companyId: id, // 施工标段id
        modelType: num, // 类型
        stationType: "4", // 拌合站类型
      };
      this.bhzDataList = [];
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            arr.map((item) => {
              this.bhzDataList.push({
                label: item.fMachinename,
                value: item.fMachineid,
              });
            });
            this.formObjText[2].options = this.bhzDataList;
          } else {
            this.$message.error(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 压浆机
    getbhjDataMethods(data, num) {
      this.bhjDataList = [];
      getMachineListByStationId({ stationId: data, modelType: num })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            arr.map((item) => {
              this.bhjDataList.push({
                label: item.fMachinename,
                value: item.fMachineid,
              });
            });
            this.formObjText[3].options = this.bhjDataList;
          } else {
            this.$message.error(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    selectChange(value, index, prop) {
      console.log("selectChange", value, index, prop);

      if (prop == "fBeamname") {
        this.formData.fMachinename = "";
        this.formData.fMachineid = "";

        this.bhzDataList.map((item) => {
          if (item.label == value) {
            this.formData.fBeamid = item.value;
            this.getbhjDataMethods(item.value, 5);
          }
        });
      }

      if (prop == "fMachinename") {
        this.bhjDataList.map((item) => {
          if (item.label == value) {
            this.formData.fMachineid = item.value;
          }
        });
      }
    },
    inputFocus(index, prop) {
      // console.log(index, prop);
      if (prop == "fWbsname") {
        this.getToken();
      }
    },

    // WBS
    async getToken() {
      await this.$http(
        "http://1.14.103.201:8300/IOTManagement/roadApi/getToken.do"
      ).then((res) => {
        if (res.status == 200) {
          // window.sessionStorage.setItem("GxBack-token", JSON.stringify(token));
          sessionStorage.setItem("GxBack-token", res.data.data.Authorizations);
          this.getWbsDataFun(this.formData.fCompanyid, "");
        }
      });
    },

    getWbsDataFun(id) {
      this.dialogEditVisible_wbs = true;
      this.loadingEditDialog_wbs = true;
      getWbsList({
        // fCompanyid: id, //云检的标段Id
        // fNodeId: num, //WBS节点Id（对应返回数据中的NodeId字段），该参数可以不传或为空（不传或为空代表的是获取第一层的WBS数据），如果该参数传了值，则代表的是获取该节点的下一层的所有数据
        // keyWord: "", //工程部位查询关键字
        fCompanyid: id, //标段id 必填
        projectId: "", //项目id 必填
        parentId: "-1", //父级id 第一级传-1  子级取上一级fId或fNodeid 必填
      })
        .then((res) => {
          if (res.errcode == 0) {
            if (res.data.data.length != 0) {
              this.tableData_Wbs = res.data.data;
              this.loadingEditDialog_wbs = false;
            } else {
              // this.$message.warning("");
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialog_wbs = false;
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
          this.loadingEditDialog_wbs = false;
        });
    },
    treeLoad(tree, treeNode, resolve) {
      this.loadingEditDialog_wbs = true;
      getWbsList({
        // fCompanyid: tree.fCompanyid, //云检的标段Id
        // // fCompanyid:"ed1bd59e-575a-4053-b23d-1bb22c49479d", //云检的标段Id
        // fNodeId: tree.fNodeid, //WBS节点Id（对应返回数据中的NodeId字段），该参数可以不传或为空（不传或为空代表的是获取第一层的WBS数据），如果该参数传了值，则代表的是获取该节点的下一层的所有数据
        // keyWord: "", //工程部位查询关键字
        fCompanyid: tree.fCompanyid, //标段id 必填
        projectId: "", //项目id 必填
        parentId: tree.fId, //父级id 第一级传-1  子级取上一级fId或fNodeid 必填
      })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog_wbs = false;
            return resolve(res.data.data);
          } else {
            this.loadingEditDialog_wbs = false;
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
          this.loadingEditDialog_wbs = false;
        });
    },
    // 点击当前行变色
    handleCurrentChange(val) {
      this.WbsRow = val;
    },
    // 行颜色
    tableRowClassName({ row }) {
      if (
        (row.fParentid == 0 && !row.children) ||
        (row.fParentid == null && !row.children)
      ) {
        return "fristColor";
      }
    },
    saveFrom() {
      if (this.WbsRow != null) {
        // if (this.WbsRow.fHaschildren == 0) {
        if (this.WbsRow.fLongname != "" && this.WbsRow.fLongname != null) {
          this.formData.fWbsname = this.WbsRow.fLongname;
        } else {
          this.formData.fWbsname = this.WbsRow.fName;
        }
        this.formData.fWbsid = this.WbsRow.fNodeid;
      
        this.formData.fWbsparentid=this.WbsRow.fParentid;

        this.dialogEditVisible_wbs = false;

        // } else {
        //   this.$message.error("请选中最底层节点！");
        // }
      }
    },
    deleFrom() {
      this.dialogEditVisible_wbs = false;
      this.WbsRow = null;
    },
    // WBS

    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      const hh = (time.getHours() + "").padStart(2, "0");
      const mm = (time.getMinutes() + "").padStart(2, "0");
      const ss = (time.getSeconds() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
      this.timeYmdHms = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    },
    // 点击当前
    rowChange(val) {
      this.rowInfo = val;
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped lang="less">
.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 110px !important;
}

/deep/ .el-col-6 {
  width: 50%;
}
</style>
